package com.calligraphy.bases.utils;

import java.util.Random;

/**
 * @Author hy
 * @Date 2018/12/13 17:04
 **/
public class KeyUtil {

    private static final int SIX = 6;
    /**
     * 生成唯一的主键
     * 格式: 时间+随机数
     * @return
     */
    public static synchronized String genUniqueKey() {
        Random random = new Random();
        Integer number = random.nextInt(900000) + 100000;

        return System.currentTimeMillis() + String.valueOf(number);
    }

    /**
     * 生成随机数
     * @return
     */
    public static synchronized String random(){
        Random random = new Random();
        String result="";
        for (int i = 0; i < SIX ;i++)
        {
            result+=random.nextInt(10);
        }
        return result;
    }


}
